import Mock from 'mockjs';
import { LoginResult, User } from './login-type'

const user:User = Mock.mock({
  name: '@ADMIN',
  avatar: '@AVATAR',
  address: '@CITY',
  position: '@POSITION'
})
const url:string = import.meta.env.VITE_APP_XXX_SERVICE_URL as string + '/login'



Mock.mock(url, 'post', ({ body }: any) => {
  let result:LoginResult = {code: 0, message: ''};

  const {account, password} = JSON.parse(body);

  if(account !== 'admin' || password !== '888888') {
    result.code = -1
    result.message = '账户名或密码错误（admin/888888）'
  } else {
    result.code = 0
    result.message = Mock.mock('@TIMEFIX').CN + '，欢迎回来'
    result.data = {
      user,
      token:'Authorization:' + Math.random(),
      expireAt: new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000)
    }
  }

  return result;
})
